package com.online.studyonline.controller;


import com.online.studyonline.pojo.Progress;
import com.online.studyonline.pojo.Result;
import com.online.studyonline.service.ProgressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/progress")
@CrossOrigin
public class ProgressController {
    @Autowired
    private ProgressService progressService;
    @GetMapping("/getProgressByUserId")
    public Result getProgressByUserId(@RequestParam("userId") Integer userId){
        return Result.success(progressService.lambdaQuery().eq(Progress::getUserId, userId).gt(Progress::getProgressNumber, 1).list());
    }
    @GetMapping("/getProgressById")
    public Result getProgressById(@RequestParam("userId") Integer userId,@RequestParam("courseId") Integer courseId){

        return Result.success(progressService.lambdaQuery().eq(Progress::getUserId, userId).eq(Progress::getCourseId, courseId).one());
    }
    @PutMapping("/updateProgress")
    public Result updateProgress(@RequestParam("progressId") Integer progressId,@RequestParam("progressNumber") Double progressNumber){
        return Result.success(progressService.lambdaUpdate().eq(Progress::getProgressId, progressId).set(Progress::getProgressNumber, progressNumber).update());
    }
    @PostMapping("/addProgress")
    public Result addProgress(@RequestBody Progress progress){
//        System.out.println(progress.getProgressId());
        return Result.success(progressService.save(progress));
    }
}
